home *** CD-ROM | disk | FTP | other *** search
- /*
- IC FSSpec Whats.c
-
- */
-
- #include <Folders.h>
- #include <Aliases.h>
-
- #include "IC Window Globals.h"
- #include "IC Types.h"
- #include "IC Dialogs.h"
- #include "IC Misc Subs.h"
- #include "IC Subs.h"
- #include "IC API.h"
- #include "IC Document.h"
- #include "IC Keys.h"
- #include "IC Globals.h"
- #include "IC StandardFile.h"
-
- #include "IC FSSpec Whats.h"
-
- OSErr ICGetVolumeStuff(StringPtr name,long date,short* vrn){
- OSErr err;
- HParamBlockRec pb;
- Str255 s;
- short i,pass;
-
- for (pass=1;pass<3;pass++){
- i=1;
- while (1){
- pb.volumeParam.ioVolIndex=i;
- i++;
- pb.volumeParam.ioNamePtr=s;
- s[0]=0;
- err=PBHGetVInfoSync(&pb);
- if (err!=noErr)
- return err;
- if (IUEqualString(name,s)==0){
- if ((pass==2)||(pb.volumeParam.ioVCrDate==date))
- break;
- }
- }
-
- if (err==noErr)
- break;
- }
-
- if (err==noErr)
- *vrn=pb.volumeParam.ioVRefNum;
-
- return err;
- }
-
- OSErr WhatOpenFSSpec(WindowType wt,short item){
- Handle spec=(Handle)0;
- Boolean valid=false;
- long loe;
- Boolean changed;
- long attr;
- CInfoPBRec pb;
- Boolean modified=false;
- FSSpec fs;
- ICFileSpecHandle sh;
-
- if (ICGetPrefHandle(GetInstance(),WindowInfo[wt].items[item]->key,&attr,&spec)==noErr)
- valid=true;
-
- ProcessAttributes(wt,item,attr);
-
- if ((valid)&&(GetHandleSize(spec)<sizeof(ICFileSpec)))
- valid=false;
-
- if (valid){
- sh=(ICFileSpecHandle)spec;
-
- if (((*sh)->alias.aliasSize==0)||(!Has_AliasMgr)){
- if (ICGetVolumeStuff((*sh)->vol_name,(*sh)->vol_creation_date,&fs.vRefNum)==noErr){
- fs.parID=(*sh)->fss.parID;
- SetPString(fs.name,1,(*sh)->fss.name);
-
- if (ICFSpGetCatInfo(&fs,0,&pb)!=noErr){
- modified=true;
- valid=false;
- }
- } else
- valid=false;
- } else {
- Munger(spec,0,(Ptr)0,sizeof(ICFileSpec)-sizeof(AliasRecord),(Ptr)&loe,0);
- if (ResolveAlias(nil,(AliasHandle)spec,&fs,&changed)!=noErr){
- modified=true;
- valid=false;
- }
- }
- }
- if (!valid){
- if ((FindFolder(kOnSystemDisk,kDesktopFolderType,true,&fs.vRefNum,&fs.parID)==noErr)&&(ICFSpGetCatInfo(&fs,-1,&pb)==noErr)){
- fs.vRefNum=pb.dirInfo.ioVRefNum;
- fs.parID=pb.dirInfo.ioDrParID;
- } else {
- fs.vRefNum=0;
- fs.parID=0;
- fs.name[0]=0;
- }
- }
-
- DisposeHandle(spec);
- BlockMoveData((Ptr)&fs,(Ptr)&(WindowInfo[wt].items[item]->fss),sizeof(FSSpec));
- WindowInfo[wt].items[item]->modified=modified;
- SetDCtlTitle(WindowInfo[wt].window,item,fs.name);
- SetDCtlEnable(WindowInfo[wt].window,item,!IsLocked(wt,item));
-
- return noErr;
- }
-
- OSErr WhatClickFSSpec(WindowType wt,short item,EventRecord* er){
- OSErr err;
- FSSpec fs;
- long dirID;
-
- err=ICStandardGetFolder(&fs,&dirID);
- if (err==noErr){
- DirtyDocument();
- WindowInfo[wt].items[item]->fss.vRefNum=fs.vRefNum;
- WindowInfo[wt].items[item]->fss.parID=dirID;
- WindowInfo[wt].items[item]->fss.name[0]=0;
-
- SetDCtlTitle(WindowInfo[wt].window,item,fs.name);
- }
- return err;
- }
-
- OSErr WhatFlushFSSpec(WindowType wt,short item){
- AliasHandle alias;
- ICFileSpec ifs;
- HParamBlockRec pb;
- OSErr err=noErr;
- long pos;
-
- if (!IsLocked(wt,item)){
- BlockMoveData((Ptr)&(WindowInfo[wt].items[item]->fss),&ifs.fss,sizeof(FSSpec));
- alias=(AliasHandle)0;
- err=(OSErr)-1;
- if (Has_AliasMgr)
- err=NewAlias((FSSpec*)0,&ifs.fss,&alias);
- if (err!=noErr){
- alias=(AliasHandle)NewHandle(sizeof(AliasRecord));
- err=MemError();
- if (err==noErr){
- (*alias)->aliasSize=0;
- (*alias)->userType=(OSType)0;
- }
- }
- if (err==noErr){
- pb.volumeParam.ioVRefNum=ifs.fss.vRefNum;
- pb.volumeParam.ioVolIndex=0;
- pb.volumeParam.ioNamePtr=ifs.vol_name;
- err=PBHGetVInfoSync(&pb);
- if (err==noErr)
- ifs.vol_creation_date=pb.volumeParam.ioVCrDate;
- }
-
- if (err==noErr){
- Munger((Handle)alias,0,(Ptr)0,0,(Ptr)&ifs,sizeof(ICFileSpec)-sizeof(AliasRecord));
- err=MemError();
- }
-
- if (err==noErr)
- err=ICMapErr(ICSetPrefHandle(GetInstance(),WindowInfo[wt].items[item]->key,ICattr_no_change,(Handle)alias));
-
- if (alias!=(AliasHandle)0)
- DisposeHandle((Handle)alias);
- }
-
- return err;
- }
-